import { VxeFormItemProps, VxeGridPropTypes } from '@gui-pkg/antdcomponents';
import { getAllStationData } from '@/api/information/rain';
import { h } from 'vue';
import { Tag } from 'ant-design-vue';
const townData = [

  {value: '大金镇', label: '大金镇'},
  {value: '四望镇', label: '四望镇'},
  {value: '梅川镇', label: '梅川镇'},
  {value: '花桥镇', label: '花桥镇'},
  {value: '田家镇街道', label: '田家镇街道'},
  {value: '余川镇', label: '余川镇'},
  {value: '大法寺镇', label: '大法寺镇'},
  {value: '刊江街道', label: '刊江街道'},
]
const typeData = [{value: "1", label: '短信'}, {value: "2", label: '电话语音'}]
const statusData = [{value: "1", label: 'I级'}, {value: "2", label: 'Ⅱ级'}, {value: "3", label: 'Ⅲ级'}, {value: "4", label: 'IV级'}, {value: "5", label: 'V级'}]
export const columns: VxeGridPropTypes.Columns = [
  {
    title: '配置名称',
    field: 'name',
    align: 'center',
    fixed: 'left',
    treeNode: true,
  },
  {
    title: '预警类型',
    field: 'warnType',
    align: 'center',
    formatter: ({cellValue}) => {
      const data: any = typeData?.find((item:any) => item.value === cellValue);
      return data?.label;
    }
  },
  {
    title: '预警等级',
    field: 'warnLevel',
    align: 'center',
    formatter: ({cellValue}) => {
      const data: any = statusData?.find((item:any) => item.value === cellValue);
      return data?.label;
    }
  },
  {
    title: '发送对象',
    field: 'target',
    align: 'center',
  },
  {
    title: '发送内容',
    field: 'msgContent',
    align: 'center',
  },
  {
    title: '是否启用',
    field: 'statue',
    align: 'center',
    slots: {
      default: ({ row }) => {
        const status = row.status;
        const enable = ~~status === 1;
        const color = enable ? 'green' : 'red';
        const text = enable ? '启用' : '不启用';
        return h(Tag, { color: color }, () => text);
      },
    },
  },
  {
    width: 160,
    title: '操作',
    align: 'center',
    slots: { default: 'action' },
    fixed: 'right',
  },
];

export const searchFormSchema: VxeFormItemProps[] = [
  {
    field: 'name',
    title: '名称',
    itemRender: {
      name: 'AInput',
    },
    span: 6,
  },
  {
    field: 'warnLevel',
    title: '预警等级',
    itemRender: {
      name: 'ASelect',
      props: {
        options: statusData,
      },
    },
    span: 6,
  },
  {
    span: 12,
    align: 'right',
    className: '!pr-0',
    itemRender: {
      name: 'AButtonGroup',
      children: [
        {
          props: { type: 'primary', content: '查询', htmlType: 'submit' },
          attrs: { class: 'mr-2' },
        },
        { props: { type: 'default', htmlType: 'reset', content: '重置' } },
      ],
    },
  },
];

export const formSchema = [
  {
    field: 'types',
    label: '通知方式',
    component: 'Select',
    required:true,
    componentProps: {
      options: typeData,
      mode: "multiple",
    },
  },
  {
    field: "warnLevel",
    label: '预警等级',
    component: "Select",
    componentProps: ({ formActionType }) => {
      const {setFieldsValue} =formActionType;
      return {
        options:statusData,
        onChange: (v: any) => {
          console.log('vvvvvvvvvvvvvvvvvvvv-----------------',v)
          state.selected = v.target.value;

        },
      };
    },
  },
  {
    field: 'town',
    label: '镇',
    component: 'Select',
    componentProps: {
      options: townData
    },
  },
  {
    label: '发送对象（村）',
    field: 'targets',
    component: 'ApiSelect',
    required:true,
    componentProps: () => {
      return {
        api: () => new Promise((resolve) => {
          getAllStationData().then((res:any) => {
            console.log('-------',res);
            resolve(res);
          });
        }),
        fieldNames: {
          label: 'stnm',
          key: 'stcd',
          value: 'stcd',
        },
      };
    },
  },
  {
    field: 'startTime',
    component: 'DatePicker',
    label: '预警时间',
    required:true,
    componentProps: {
      valueFormat: 'YYYY-MM-DD HH:mm:ss',
      showTime:true,
    },
  },
  {
    field: 'msgContent',
    label: '发送内容',
    component: 'InputTextArea',
    required:true,
  },
];
